<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="调用时间" style="width: 308px">
        <el-date-picker
          v-model="dateRange"
          value-format="YYYY-MM-DD HH:mm:ss"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="[
            new Date(2000, 1, 1, 0, 0, 0),
            new Date(2000, 1, 1, 23, 59, 59),
          ]"
        ></el-date-picker>
      </el-form-item>

      <el-form-item label="补发类型" prop="reissueType">
        <el-select
          @change="handleQuery"
          v-model="queryParams.reissueType"
          placeholder="选择补发类型"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in sys_demands_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['system:aiRechargeRecords:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        v-model:showSearch="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="aiRechargeRecordsList2">
      <template v-for="(item, index) in aiRechargeRecordsList">
        <el-table-column :label="item.itemName" align="center">
          {{ item.itemCount }}
        </el-table-column>
      </template>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script setup name="AiRechargeRecords">
import { queryHairstyleDemandsGroupDataApi } from "@/api/system/aiRechargeRecords";

const { proxy } = getCurrentInstance();
const { sys_demands_type } = proxy.useDict("sys_demands_type");

const aiRechargeRecordsList = ref([]);
const aiRechargeRecordsList2 = ref([]);
const open = ref(false);
const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const dateRange = ref([]);

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    rechargeAmount: undefined,
    points: undefined,
    reissueType: "发丝长度",
  },
});

const { queryParams, form, rules } = toRefs(data);

/** 查询极客小程序ai换发充值记录列表 */
function getList() {
  loading.value = true;
  if (dateRange.value != null && dateRange.value.length > 1) {
    queryParams.value.beginTime = dateRange.value[0];
    queryParams.value.endTime = dateRange.value[1];
  }
  queryHairstyleDemandsGroupDataApi(queryParams.value).then((response) => {
    console.log(response.data);
    if (response.data.length === 0) {
      loading.value = false;
      return;
    }
    aiRechargeRecordsList2.value = response.data;
    aiRechargeRecordsList.value = response.data[0].geekAiHairDemandsItemList;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    rechargeAmount: null,
    points: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null,
    delFlag: null,
  };
  dateRange.value = null;
  proxy.resetForm("aiRechargeRecordsRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download(
    "/business/aiHairstyleDemands/exportGroupData",
    {
      ...queryParams.value,
    },
    `aiRechargeRecords_${new Date().getTime()}.xlsx`
  );
}

getList();
</script>
